package lol_stream_manager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CMDThread extends Thread {
    
    String name;
    String command;
    long maxTime;
    
    public CMDThread( String name, String command, long maxTime ){
        this.name = name;
        this.command = command;
        this.maxTime = maxTime;
    }
    
    @Override
    public void run(){
        System.out.println("Thread started: " + name + " (" + command + ")");
        try {
            Runtime rt = Runtime.getRuntime();
            Process p = rt.exec( command );
//            BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
            long t = System.currentTimeMillis();
//            String line;
            while( System.currentTimeMillis() - t < maxTime ){}
            
            p.destroy();
            System.out.println("Thread exited: " + name);
            
        } catch (IOException e) {}
    }
    
}
